package com.goodfox.web.generic.account.entity;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.GrantedAuthorityImpl;
import org.springframework.security.core.userdetails.UserDetails;

import com.goodfox.web.generic.authority.entity.Resources;
import com.goodfox.web.generic.organization.entity.Organization;
import com.goodfox.web.generic.provide.annotation.DbEntity;
import com.goodfox.web.generic.provide.annotation.DbField;
import com.goodfox.web.generic.provide.entity.Grade;
import com.goodfox.web.generic.role.entity.Role;

/**
 * @author qin gt
 *
 */
@DbEntity(comment="人员账号",table="DSYS_ACCOUNT")
public class Account implements UserDetails {

	@DbField(comment="实例化UID",meaning=false)
	private static final long serialVersionUID = 5162281888120492537L;

	@DbField(comment="账户Id",column="ACT_ID",export=false,pk=true,javaType="String",dataType="VARCHAR2",required=true,maxLength=50)
	private String actId;

	@DbField(comment="所属组织机构Id",column="ORG_ID",export=false,javaType="String",dataType="VARCHAR2",maxLength=50)
	private String orgId;

	@DbField(comment="用户名",column="ACT_NAME",javaType="String",dataType="VARCHAR2",maxLength=15)
	private String actName;

	@DbField(comment="密码",column="ACT_PASSWORD",export=false,javaType="String",dataType="VARCHAR2",maxLength=30)
	private String actPassword;

	@DbField(comment="姓名",column="MEM_NAME",javaType="String",dataType="VARCHAR2",maxLength=30)
	private String memName; 

	@DbField(comment="性别",column="MEM_SEX",export=false,javaType="String",dataType="VARCHAR2",maxLength=2)
	private String memSex; 
	
	@DbField(comment="生日",column="MEM_BIRTHDAY",javaType="Date",dataType="DATE")
	private Date memBirthday; 

	@DbField(comment="家庭住址",column="MEM_ADDRESS",javaType="String",dataType="VARCHAR2",maxLength=100)
	private String memAddress; 

	@DbField(comment="家庭邮编",column="MEM_ZIP",javaType="String",dataType="VARCHAR2",maxLength=6)
	private String memZip;

	@DbField(comment="身份证",column="MEM_IDCARD",javaType="String",dataType="VARCHAR2",maxLength=18)
	private String memIdCard; 

	@DbField(comment="移动电话",column="MEM_MOBILE",javaType="String",dataType="VARCHAR2",maxLength=11)
	private String memMobile; 

	@DbField(comment="固定电话",column="MEM_PHONE",javaType="String",dataType="VARCHAR2",maxLength=13)
	private String memPhone; 

	@DbField(comment="电子邮箱",column="MEM_EMAIL",javaType="String",dataType="VARCHAR2",maxLength=60)
	private String memEmail; 

	@DbField(comment="状态",column="ACT_STATE",export=false,javaType="String",dataType="VARCHAR2",maxLength=2)
	private String actState;

	@DbField(comment="备注",column="ACT_REMARK",export=false,javaType="String",dataType="VARCHAR2",maxLength=200)
	private String actRemark;
	
	@DbField(comment="角色Id",column="ROLE_ID",javaType="String",dataType="VARCHAR2",export=false,maxLength=50)
	private String roleId;
	
	@DbField(comment="角色",column="ROLE_ID",fk=true,linkTable="DSYS_ROLE",linkColumn="ROLE_ID",export=false,direct=false)
    private Role role;
	
	@DbField(comment="组织机构",column="ORG_ID",direct=false)
	private String orgName;

	@DbField(comment="角色",column="ROLE_ID",direct=false)
	private String roleName;

	@DbField(comment="性别",column="MEM_SEX",direct=false)
	private String sexName;
	
	@DbField(comment="资源",fk=true,linkTable="DSYS_RESOURCES",linkColumn="RSE_ID",export=false,direct=false)
	private Set<Resources>  resourcelSet = new HashSet<Resources>();

	@DbField(comment="所属组织机构",export=false,direct=false)
	private Organization actOrganization;


	/** 覆盖spring security父类方法 start */
	
	@Override
	public Collection<GrantedAuthority> getAuthorities() {
		List<GrantedAuthority> authorityList = new ArrayList<GrantedAuthority>();  
		authorityList.add(new GrantedAuthorityImpl(role.getRolePower())); 
        return authorityList;
	}

	@Override
	public String getPassword() {
		return actPassword;
	}

	@Override
	public String getUsername() {
		return actPassword;
	}

	@Override
	public boolean isAccountNonExpired() {
		return true;
	}

	@Override
	public boolean isAccountNonLocked() {
		return true;
	}

	@Override
	public boolean isCredentialsNonExpired() {
		return true;
	}

	@Override
	public boolean isEnabled() {
		boolean bool=false;
		if("1".equals(actState)){
			bool=true;
		}
		return bool;
	}
	
	/** 覆盖spring security父类方法 end */


	public String getActName() {
		return actName;
	}

	public String getActId() {
		return actId;
	}

	public void setActId(String actId) {
		this.actId = actId;
	}

	public String getOrgId() {
		return orgId;
	}

	public void setOrgId(String orgId) {
		this.orgId = orgId;
	}

	public void setActName(String actName) {
		this.actName = actName;
	}

	public String getActPassword() {
		return actPassword;
	}

	public void setActPassword(String actPassword) {
		this.actPassword = actPassword;
	}

	public String getMemName() {
		return memName;
	}

	public void setMemName(String memName) {
		this.memName = memName;
	}

	public String getMemSex() {
		return memSex;
	}

	public void setMemSex(String memSex) {
		this.memSex = memSex;
	}

	public Date getMemBirthday() {
		return memBirthday;
	}

	public void setMemBirthday(Date memBirthday) {
		this.memBirthday = memBirthday;
	}

	public String getMemAddress() {
		return memAddress;
	}

	public void setMemAddress(String memAddress) {
		this.memAddress = memAddress;
	}

	public String getMemZip() {
		return memZip;
	}

	public void setMemZip(String memZip) {
		this.memZip = memZip;
	}

	public String getMemIdCard() {
		return memIdCard;
	}

	public void setMemIdCard(String memIdCard) {
		this.memIdCard = memIdCard;
	}

	public String getMemMobile() {
		return memMobile;
	}

	public void setMemMobile(String memMobile) {
		this.memMobile = memMobile;
	}

	public String getMemPhone() {
		return memPhone;
	}

	public void setMemPhone(String memPhone) {
		this.memPhone = memPhone;
	}

	public String getMemEmail() {
		return memEmail;
	}

	public void setMemEmail(String memEmail) {
		this.memEmail = memEmail;
	}

	public String getActState() {
		return actState;
	}

	public void setActState(String actState) {
		this.actState = actState;
	}

	public String getActRemark() {
		return actRemark;
	}

	public void setActRemark(String actRemark) {
		this.actRemark = actRemark;
	}

	public String getRoleId() {
		return roleId;
	}

	public void setRoleId(String roleId) {
		this.roleId = roleId;
	}

	public Role getRole() {
		return role;
	}

	public void setRole(Role role) {
		this.role = role;
	}

	public String getOrgName() {
		return orgName;
	}

	public void setOrgName(String orgName) {
		this.orgName = orgName;
	}

	public Set<Resources> getResourcelSet() {
		return resourcelSet;
	}

	public void setResourcelSet(Set<Resources> resourcelSet) {
		this.resourcelSet = resourcelSet;
	}

	public String getRoleName() {
		return roleName;
	}

	public void setRoleName(String roleName) {
		this.roleName = roleName;
	}

	public String getSexName() {
		return sexName;
	}

	public void setSexName(String sexName) {
		this.sexName = sexName;
	}

	public Organization getActOrganization() {
		return actOrganization;
	}

	public void setActOrganization(Organization actOrganization) {
		this.actOrganization = actOrganization;
	}

}
